//
// Created by LiuYou on 2021/8/2.
//

#include <cstdlib>
#include <cstdio>
#include <iostream>


bool find(int* matrix, int rows, int columns, int number) {
    bool value = false;
    if (matrix != nullptr && rows > 0 && columns > 0) {
        int row = 0;
        int column = columns - 1;
        while (row < rows && column >= 0) {
            if (matrix[row * columns + column] == number) {
                value = true;
                break;
            } else if (matrix[row * columns + column] > number) {
                --column;
            } else {
                ++row;
            }
        }
    }

    return value;
}


/*
 * 二维数组
 */
int main() {
    int array[][4] = {
            {1, 2, 8,  9},
            {2, 4, 9,  12},
            {4, 7, 10, 13},
            {6, 8, 11, 15}
    };
    for (const auto& item : array) {
        for (const auto& obj : item) {
            std::cout << obj << " ";
        }
        std::cout << std::endl;
    }
    // 二维数组与指针。这个问题不是当前的重点, 之后会复习到的。
    std::cout << find((int*) array, 4, 4, 7 ) << std::endl;


    exit( 0 );
}